// uapi.js
const install = (Vue, vm) => {	
	// 获取用户信息
	let getUserInfo = async () => {
		let res = await vm.$u.get('/member/userinfo')
		let { last_week, this_week, total, userinfo } = res.data.result
		return { last_week, this_week, total, userinfo }
	}
	
	// 获取并更新用户信息
	let updateUserInfo = async () => {
		let { last_week, this_week, total, userinfo } = await getUserInfo()
		vm.$store.commit('setUserInfo', userinfo)
	}
  
  // 获取企业详情
  let getCompanyDetail = async (id) => {
    let res = await vm.$u.get(`/company/detail?id=${id}`)
    let { company } = res.data.result
    return { company }
  }
  
  // 获取个人名片夹
  let getPersonlCards = async () => {
    let res = await vm.$u.get('/myvcard/friend/list')
    let { company, list } = res.data.result
    return { company, list }
  }
  
  // 获取导入名片夹
  let getImportCards = async (id) => {
    let res = await vm.$u.get('/company/import/list?id=' + id)
    let { list } = res.data.result
    return { list }
  }

  vm.$u.api = {
    getUserInfo,
		updateUserInfo,
    getCompanyDetail,
    getPersonlCards,
    getImportCards
  };
}

export default {
  install
}